import {createStore} from 'openinula'
export const getStore = createStore({
  // id 用于标识一个Store对象
  id: 'user',

  // state 用于存放数据
  state: {
    data: {
      list: [
        { id: 1, name: 'liming', age: 18 },
        { id: 2, name: 'xiaohong', age: 20 },
      ],
    },
    loading: false,
    selectUsers: [1],
  },

  // action 用于修改state中的数据
  actions: {
    addUser(state, payload) {
      state.data.list.push(payload);
    },

    addSelectedUser(state, payload) {
      state.selectUsers.push(payload);
    },

    setLoading(state,payload) {
      state.loading = payload;
    },
  },

  // computed 用于获取state状态变量的计算属性
  computed: {
    users: state => state.data.list,

    userCount(states) {
      // 通过this获取其他computed的值
      return this.users.length;
    },
  },
});